# -*- coding: utf-8 -*-
from sqlalchemy import *
from sqlalchemy.sql import select
from sqlalchemy.schema import *
# create the engine for oracle db  
# we need to install cx_Oracle and sqlalchemy in advance. 
db_engine=create_engine('oracle://gis:ndtvgis@192.168.20.79:1521/GIS', echo=True)
# test the ddl to db  
# this is tested in VM and works fine.  
# db_engine.execute("create table zy_user(name varchar2(10), address varchar2(50))")  
  
# reflect the table into sqlalchemy  
# we should use the meta to do the reflect in version 0.9 
meta=MetaData()
t=Table('tegjd',meta,autoload=True,autoload_with=db_engine)
# autoload the keys  
# print t.c.keys()

# create the insert script  
# ins=t.insert()  
# print str(ins)

# check all the column names and do a select to fetch the data directly from table 
conn=db_engine.connect()  
s=select([t]).where(t.c.bm=='HS.ZFY/SQY/GJD01') # 提供查询条件  
result=conn.execute(s)  
for row in result:  
    print row[t.c.id0],row[t.c.mc] # 看这里，直接用t.c.name就可以调用name列的值了，c代表column。不用做映射，不用配置文件，简单到无语吧？...  
    print row
# remember to close the cursor  
result.close()  